<%@ page import="org.example.demo1.Entity.User" %>
<%@ page import="java.lang.reflect.Array" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>书羊网 - 书库</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
          integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <style>
        /* 小说卡片样式 */
        .novel-card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            height: 100%;
        }
        
        .novel-card:hover {
            transform: translateY(-8px);
            box-shadow: 0 10px 20px rgba(0,0,0,0.1) !important;
        }
        
        .novel-title {
            font-size: 16px;
            font-weight: bold;
            margin-bottom: 5px;
            display: -webkit-box;
            -webkit-line-clamp: 1;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        
        .author-name {
            font-size: 14px;
            color: #666;
        }
        
        .novel-introduction {
            font-size: 13px;
            color: #777;
            display: -webkit-box;
            -webkit-line-clamp: 2;
            -webkit-box-orient: vertical;
            overflow: hidden;
            text-overflow: ellipsis;
            max-height: 40px;
        }
        
        .novel-info {
            flex: 1;
            min-width: 0; /* 确保文本可以正确截断 */
        }
        
        .novel-cover {
            flex-shrink: 0; /* 防止封面图片被压缩 */
        }
        
        .novel-tag {
            display: inline-block;
            padding: 2px 8px;
            background-color: #f0f0f0;
            color: #666;
            border-radius: 4px;
            font-size: 12px;
            margin-right: 5px;
            margin-bottom: 5px;
        }
        
        /* 分类标签样式 */
        .category-tag {
            cursor: pointer;
            transition: all 0.2s;
            border-radius: 20px;
            padding: 6px 15px;
            margin-right: 10px;
            margin-bottom: 10px;
            background-color: #f8f9fa;
            border: 1px solid #dee2e6;
        }
        
        .category-tag:hover {
            background-color: #e9ecef;
        }
        
        .category-tag.active {
            background-color: #e74c3c;
            color: white;
            border-color: #e74c3c;
        }
        
        /* 筛选栏样式 */
        .filter-bar {
            background-color: #f8f9fa;
            border-radius: 8px;
            padding: 15px;
            margin-bottom: 20px;
        }
        
        /* 页面标题样式 */
        .section-title {
            position: relative;
            margin-bottom: 25px;
            padding-left: 15px;
            font-weight: bold;
            border-left: 4px solid #e74c3c;
        }
        
        /* 加载更多按钮 */
        .load-more-btn {
            background-color: #f8f9fa;
            border: 1px solid #dee2e6;
            color: #495057;
            transition: all 0.3s;
        }
        
        .load-more-btn:hover {
            background-color: #e9ecef;
        }
    </style>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">  <!-- 添加 fixed-top -->
    <div class="container">  <!-- 修改为 container 替代 container-fluid -->
        <a class="navbar-brand py-0" href="#">  <!-- 添加 py-0 减少纵向间距 -->
            <img src="https://mysteriouslamb.oss-cn-hangzhou.aliyuncs.com/icon.jpg" alt="" width="30" height="30">
            书羊网
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav me-auto">  <!-- 修改: me-3 变为 me-auto -->
                <li class="nav-item px-1">  <!-- 添加水平间距 -->
                    <a class="nav-link" href="${pageContext.request.contextPath}/MainPage/functionPage/index.jsp">首页</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link active" aria-current="page" href="#">书库</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="${pageContext.request.contextPath}/MainPage/functionPage/bookshelf.jsp">书架</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="#">角色扮演</a>
                </li>
                
                <c:if test="${not empty permission}">
                    <c:set var="hasAuthorPermission" value="false" />
                    <c:forEach var="perm" items="${permission}">
                        <c:if test="${perm == 2}">
                            <c:set var="hasAuthorPermission" value="true" />
                        </c:if>
                    </c:forEach>
                    
                    <c:choose>
                        <c:when test="${hasAuthorPermission}">
                            <li class="nav-item">
                                <a class="nav-link" href="${pageContext.request.contextPath}/MainPage/functionPage/authorWorkspace.jsp">作者工作台</a>
                            </li>
                        </c:when>
                        <c:otherwise>
                            <li class="nav-item">
                                <a class="nav-link" href="#">成为作者</a>
                            </li>
                        </c:otherwise>
                    </c:choose>
                </c:if>
            </ul>
            <form class="d-flex mx-auto" id="searchForm" style="width: 40%; max-width: 400px;"> <!-- 修改: 添加 mx-auto 和 style -->
                <input class="form-control me-2 rounded-pill" type="search" placeholder="请输入书名或作者名" aria-label="Search" id="searchInput">
                <!-- 添加圆角 -->
                <button class="btn btn-outline-success rounded-pill" type="submit" style="min-width: 60px;">搜索</button> <!-- 添加圆角和最小宽度 -->
            </form>
            <div class="ms-auto d-flex align-items-center gap-3 me-3"> <!-- 添加右侧间距 -->
                <a class="d-flex align-items-center text-decoration-none" href="#" style="gap:12px">
                    <img src="${user.avatar_url}" alt="用户头像"
                         class="rounded-circle shadow-sm transition-all"
                         width="45" height="45"
                         style="transition:0.3s">
                    <div class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle fw-bold text-dark p-2 rounded-3"
                           href="#"
                           role="button"
                           data-bs-toggle="dropdown"
                           style="transition:0.3s">
                            ${user.username}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end border-0 shadow-sm">
                            <li><a class="dropdown-item py-2 text-danger rounded-2" href="${pageContext.request.contextPath}/API/user/logout">🚪 退出登录</a></li>
                        </ul>
                    </div>
                </a>
            </div>
        </div>
    </div>
</nav>

<!-- 主要内容区域 -->
<div class="container" style="margin-top: 80px; padding-top: 20px;">
    <!-- 书库标题 -->
    <h2 class="section-title mt-4 mb-4">全部作品</h2>
    
    <!-- 筛选栏 -->
    <div class="filter-bar mb-4">
        <div class="row">
            <div class="col-12 mb-3">
                <strong class="me-3">分类：</strong>
                <span id="category-filter-container"> <!-- 添加ID -->
                    <!-- 分类标签将由JS动态渲染 -->
                </span>
            </div>
            <!-- 新增子类容器 -->
            <div class="col-12 mb-3" id="subcategory-container" style="display: none; padding-left: 25px;">
                <strong class="me-3">子类：</strong>
                <span id="subcategory-filter-container">
                    <!-- 子类标签将由JS动态渲染 -->
                </span>
            </div>
            <div class="col-12 mb-3">
                <strong class="me-3">状态：</strong>
                <span class="category-tag active" data-status="all">全部</span>
                <span class="category-tag" data-status="0">连载</span>
                <span class="category-tag" data-status="1">完结</span>
            </div>
            <div class="col-12">
                <strong class="me-3">字数：</strong>
                <span class="category-tag active" data-word-count="all">全部</span>
                <span class="category-tag" data-word-count="lt30w">30万以下</span>
                <span class="category-tag" data-word-count="30w-50w">30—50万</span>
                <span class="category-tag" data-word-count="50w-100w">50-100万</span>
                <span class="category-tag" data-word-count="100w-200w">100-200万</span>
                <span class="category-tag" data-word-count="gt200w">200万以上</span>
            </div>
        </div>
    </div>
    
    <!-- 小说列表 -->
    <div id="novels-container" class="row row-cols-1 row-cols-sm-2 row-cols-md-3 g-4"></div>
    
    <!-- 分页区域 -->
    <div id="pagination-container" class="mt-4 d-flex justify-content-center"></div>
    
    <!-- 加载更多按钮 -->
    <div class="text-center mt-4 mb-5">
        <button id="loadMoreBtn" class="btn load-more-btn px-5 py-2">
            <i class="bi bi-arrow-down-circle me-2"></i>加载更多
        </button>
    </div>
</div>

<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
        integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
        crossorigin="anonymous"></script>
<!-- 引入小说展示JS -->
<script src="${pageContext.request.contextPath}/MainPage/functionPage/libraryDisplay.js"></script>
</body>
</html>